package com.minimalist.common.feign.fallback.lindi;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.purchaseindexrecord.LindiPurchaseIndexRecordQueryVO;
import com.minimalist.common.entity.lindi.vo.purchaseindexrecord.LindiPurchaseIndexRecordVO;
import com.minimalist.common.feign.client.lindi.LindiPurchaseIndexRecordFeignClient;
import com.minimalist.common.feign.config.BaseFallbackFactory;
import com.minimalist.common.response.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

/**
 * 林地指标交易平台_购买指标记录Feign客户端降级工厂
 * 使用FallbackFactory可以获取到异常信息，便于问题排查
 *
 * @author 11987
 */
@Component
public class LindiPurchaseIndexRecordFeignClientFallbackFactory extends BaseFallbackFactory<LindiPurchaseIndexRecordFeignClient>{
    private static final Logger log = LoggerFactory.getLogger(LindiPurchaseIndexRecordFeignClientFallbackFactory.class);


    @Override
    public LindiPurchaseIndexRecordFeignClient create(Throwable cause){
        return new LindiPurchaseIndexRecordFeignClient(){

            @Override
            public R<?> addPurchaseIndexRecord(LindiPurchaseIndexRecordVO purchaseIndexRecordVO){
                logServiceUnavailable("添加购买指标记录", purchaseIndexRecordVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "添加购买指标记录失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> deletePurchaseIndexRecordByPurchaseIndexRecordId(Long purchaseIndexRecordId){
                logServiceUnavailable("删除购买指标记录", purchaseIndexRecordId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "删除购买指标记录失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> updatePurchaseIndexRecordByPurchaseIndexRecordId(LindiPurchaseIndexRecordVO purchaseIndexRecordVO){
                logServiceUnavailable("修改购买指标记录", purchaseIndexRecordVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "修改购买指标记录失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<PageResp<LindiPurchaseIndexRecordVO>> getPagePurchaseIndexRecordList(LindiPurchaseIndexRecordQueryVO queryVO){
                logServiceUnavailable("分页查询购买指标记录列表", queryVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "分页查询购买指标记录列表失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<LindiPurchaseIndexRecordVO> getPurchaseIndexRecordByPurchaseIndexRecordId(Long purchaseIndexRecordId){
                logServiceUnavailable("根据购买指标记录ID查询购买指标记录", purchaseIndexRecordId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "根据购买指标记录ID查询购买指标记录失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> deletePurchaseIndexRecordFileByFileId(Long fileId){
                logServiceUnavailable("删除购买指标记录文件", fileId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "删除购买指标记录文件失败，服务不可用: " + cause.getMessage());
            }
        };
    }
}

